import Boom from '@hapi/boom';

/**
 * x       xx   xx       xxx
 * 错误等级-模块-错误类型-错误号
 *
 *
 * 等级：
 * 	 0 - warning
 * 	 1 - error
 * 	 2 - fatal
 * 错误类型：
 *   00 - 内部错误，不会发送到出去
 *   01 - 开放错误，发送回前端
 */
export const defaultErrorCodes = {
	// #region 01.任务队列
	'[01]任务队列处理失败': {
		category: 0x1,
		level: 2,
		isPublic: 0,
		index: 0x1,
		code: 0x20100001,
	},
	'[01]任务队列任务执行失败': {
		code: 0x10100002,
	},
	'[01]更新结果失败': {
		code: 0x10100003,
	},
	'[01]更新任务状态失败': {
		code: 0x10100004,
	},
	'[01]查询Mongo任务记录失败': {
		code: 0x10100005,
	},
	'[01]停止任务：删除任务失败': {
		code: 0x10100006,
	},
	'[01]删除任务：查找任务mongo记录失败': {
		code: 0x10100007,
	},
	'[01]删除任务：删除任务失败': {
		code: 0x10100008,
	},
	'[01]忽略告警:查找任务mongo记录失败': {
		code: 0x10100009,
	},
	'[01]忽略告警:没有找到对应mongo记录': {
		code: 0x1010000a,
	},
	'[01]忽略告警:不能修改非最后一次任务状态': {
		code: 0x1010100b,
	},
	'[01]忽略告警：更新mongo记录失败': {
		code: 0x1010000c,
	},
	'[01]重试监测任务失败': {
		code: 0x1010000d,
	},
	'[01][自定义监测任务]查找任务mongo记录失败': {
		code: 0x1010000e,
	},
	'[01][自定义监测任务]没有找到对应mongo记录': {
		code: 0x1010000f,
	},
	'[01][自定义监测任务]添加任务失败': {
		code: 0x10100010,
	},
	'[01]新增可用性任务数据失败': {
		code: 0x10100011,
	},
	'[01]新增非可用性任务数据失败': {
		code: 0x10100012,
	},
	'[01]取消忽略告警:查找任务mongo记录失败': {
		code: 0x10100013,
	},
	'[01]取消忽略告警:没有找到对应mongo记录': {
		code: 0x10100014,
	},
	'[01]取消忽略告警:不能修改非最后一次任务状态': {
		code: 0x10101015,
	},
	'[01]取消忽略告警：更新mongo记录失败': {
		code: 0x10100016,
	},
	'[01][修改告警状态]查找任务mongo记录失败': {
		code: 0x10100017,
	},
	'[01][修改告警状态]没有找到对应mongo记录': {
		code: 0x10100018,
	},
	'[01][修改告警状态]不能修改非最后一次任务状态': {
		code: 0x10100019,
	},
	'[01][修改告警状态]更新mongo记录失败': {
		code: 0x1010001a,
	},
	'[01][定时任务创建新任务]查询Mongo关联Task记录': {
		code: 0x1010001d,
	},
	'[01][定时任务创建新任务]更新Mongo关联Task记录': {
		code: 0x1010001e,
	},
	'[01][更新ref的子任务执行状态]查找任务失败': {
		code: 0x1010001f,
	},
	'[01][更新ref的子任务执行状态]ref更新状态失败': {
		code: 0x10100020,
	},
	'[01][下发任务]更新周期任务首次执行时间失败': {
		code: 0x10100021,
	},
	'[01][下发任务]查询关联Mongo记录失败': {
		code: 0x00301022,
	},
	'[01]资产未通过验证不允许下发监测任务': {
		code: 0x00301023,
	},
	'[01]更新队列任务失败': {
		code: 0x00100024,
	},
	'[01]监测任务状态回调更新失败': {
		code: 0x00100025,
	},
	'[01]重试任务:查找任务mongo记录失败': {
		code: 0x00100026,
	},
	'[01]终止任务:查找任务mongo记录失败': {
		code: 0x00100027,
	},
	'[01]可用扫描URL页面数已达到套餐上限，将不再下发监测任务': {
		code: 0x00101028,
	},
	'[01]查询相同类型任务失败': {
		code: 0x00101029,
	},
	'[01]已有相同类型任务正在执行': {
		code: 0x0010102a,
	},
	'[01]套餐已过期': {
		code: 0x0010102b,
	},
	'[01]当前域名的绑定IP是保留地址': {
		code: 0x0010102c,
	},
	'[01]当前资产无法解析': {
		code: 0x0010102d,
	},
	'[01]请求任务调度失败': {
		code: 0x0010102e,
	},
	// #endregion

	// #region 02 资产监测
	'[02]资产监测Worker子域名扫描失败': {
		code: 0x10200001,
	},
	'[02]监测Worker任务创建失败': {
		code: 0x10200002,
	},
	'[02]资产监测Worker端口扫描任务失败': {
		code: 0x00200003,
	},
	'[02]资产监测Worker绑定域名扫描任务失败': {
		code: 0x00200004,
	},
	'[02]资产监测Worker IP关联信息扫描失败': {
		deleted: true,
		code: 0x00200005,
	},
	'[02]资产监测Worker更新资产失败': {
		code: 0x10200006,
	},
	'[02]资产监测Worker子域名扫描结果为空': {
		deleted: true,
		code: 0x10200007,
	},
	'[02]自定义扫描任务：查询关联资产mongo记录失败': {
		code: 0x10200008,
	},
	'[02]自定义扫描任务：创建任务失败': {
		code: 0x10200009,
	},
	'[02]资产结果统计：查询关联Task失败': {
		code: 0x1020000a,
	},
	'[02]更新的资产未通过验证': {
		code: 0x0020100b,
	},
	'[02]监测结果处理：关联Mongo记录查询失败': {
		code: 0x0020000c,
	},
	'[02]不允许更新未通过验证的资产': {
		code: 0x0020100d,
	},
	// #endregion

	// #region 03 扫描任务配置
	'[03]更新资产扫信息失败': {
		code: 0x10300003,
	},
	'[03]更新资产: 禁用任务失败': {
		code: 0x10300004,
	},
	'[03]更新资产: 从队列获取任务信息失败': {
		code: 0x10300005,
	},
	'[03]更新资产: 添加新任务失败': {
		code: 0x10300006,
	},
	'[03]更新资产: 全局禁用任务': {
		code: 0x10300007,
	},
	'[03]更新资产: 全局启动添加任务': {
		code: 0x10300008,
	},
	'[03]更新资产: 全局启动禁用任务': {
		code: 0x10300009,
	},
	'[03]创建监测任务配置失败': {
		code: 0x1030000a,
	},
	'[03][创建监测任务配置]更新任务状态失败': {
		code: 0x1030000b,
	},
	'[03]syncTask: 更新taskStatusId失败': {
		code: 0x1030000c,
	},
	'[03]deleteTask: 删除Queue任务失败': {
		code: 0x1030000d,
	},
	'[03]deleteTask: 删除任务失败': {
		code: 0x1030000e,
	},
	'[03]syncTask: 查询job记录': {
		code: 0x1030000f,
	},
	'[03]syncTask: 更新job记录': {
		code: 0x10300010,
	},
	'[03]创建任务：创建网站画像任务失败': {
		code: 0x10300011,
	},
	'[03]所有权检查：对应Job Mongo记录查询失败': {
		code: 0x10300012,
	},
	'[03]所有权检查：检查失败': {
		code: 0x10300013,
	},
	'[03]所有权检查：对应Job Mongo记录更新失败': {
		code: 0x10300014,
	},
	'[03][批量创建任务]传入参数校验失败': {
		code: 0x10300015,
	},
	'[03][批量创建任务]查询关联用户失败': {
		code: 0x10300016,
	},
	'[03][批量创建任务]可用性任务查询关联资产失败': {
		code: 0x10300017,
	},
	'[03]deleteResult: 删除历史任务数据失败': {
		code: 0x10300018,
	},
	'[03]批量创建任务失败': {
		code: 0x10300019,
	},
	'[03]任务配置列表下载失败': {
		code: 0x1030001a,
	},
	'[03]添加资产失败：当前资产已添加': {
		code: 0x1030101b,
	},
	'[03][更新任务配置]没有查询到对应Mongo任务': {
		code: 0x1030001c,
	},
	'[03]添加资产：传入参数错误': {
		code: 0x1030101d,
	},
	'[03]删除资产关联资产变动任务': {
		code: 0x1030001e,
	},
	'[03][批量创建任务]未找到可用性监测任务关联的资产监测任务': {
		code: 0x1030101f,
	},
	'[03]更新资产: 余额不足': {
		code: 0x10301020,
	},
	'[03]更新资产: 余额扣除失败': {
		code: 0x10300021,
	},
	'[03]删除资产: 余额扣除失败': {
		code: 0x10300022,
	},
	'[03]添加资产: 余额不足': {
		code: 0x10300023,
	},
	'[03]添加资产: 余额扣除失败': {
		code: 0x10300024,
	},
	'[03]更新资产: 查找资产失败': {
		code: 0x10300025,
	},
	'[03]更新资产: 创建资产变动任务失败': {
		code: 0x10300026,
	},
	'[03]更新资产: 删除资产变动任务失败': {
		code: 0x10300027,
	},
	'[03]更新资产信息: 查找资产失败': {
		code: 0x10300028,
	},
	'[03]更新资产信息: 更新asset记录': {
		code: 0x10300029,
	},
	'[03]更新资产信息: 更新taskStatusId失败': {
		code: 0x1030002a,
	},
	'[03]更新资产信息: 创建资产变动任务失败': {
		code: 0x10300030,
	},
	'[03]更新资产信息: 删除资产变动任务失败': {
		code: 0x10300031,
	},
	'[03]更新资产信息: 从队列获取任务信息失败': {
		code: 0x10300032,
	},
	'[03]删除资产变动任务: 删除资产变动扫描任务数据失败': {
		deleted: true,
		code: 0x10300033,
	},
	'[03]更新用户同意免责条款时间失败': {
		code: 0x10300034,
	},
	'[03]修改资产验证状态失败': {
		code: 0x10300035,
	},
	'[03]添加资产：检查资产是否已添加失败': {
		code: 0x10300036,
	},
	'[03]更新的资产未通过验证': {
		code: 0x00301037,
	},
	'[03]认证关联Job查询失败': {
		code: 0x00300038,
	},
	'[03]不允许更新未通过验证的资产': {
		code: 0x00300039,
	},
	'[03]创建任务：检查是否启用创宇盾失败': {
		code: 0x1030003a,
	},
	'[03]添加资产：查询关联balance记录失败': {
		code: 0x1030003b,
	},
	'[03]编辑资产：查询关联balance记录失败': {
		code: 0x1030003c,
	},
	'[03][批量创建任务]可用性任务查询关联用户资产失败': {
		code: 0x1030003d,
	},
	'[03][批量创建任务]可用性任务关联用户资产未认证': {
		code: 0x1030003e,
	},
	'[03]资产所属权验证失败：套餐已过期': {
		code: 0x1030103f,
	},
	'[03]网站画像：当前资产未接入知道创宇云防御，无法使用网站画像功能': {
		code: 0x10301041,
	},
	'[03]更新任务配置失败': {
		code: 0x10301042,
	},
	// #endregion

	// #region 04 SSL任务
	'[04]SSL监测任务创建失败': {
		code: 0x10400001,
	},
	// #endregion

	// #region 05 漏洞扫描
	'[05]漏洞扫描: 漏洞扫描任务创建失败': {
		code: 0x10500001,
	},
	'[05]漏洞扫描: 漏洞扫描检查任务状态失败': {
		code: 0x10500002,
	},
	'[05]漏洞扫描: 漏洞扫描检查任务删除失败': {
		code: 0x10500003,
	},
	// #endregion

	// #region 06 cyd配置
	'[06]安全事件监测任务创建失败': {
		code: 0x10600001,
	},
	// #endregion

	// #region 07 cyd配置
	'[07]创宇盾源站配置检查失败': {
		code: 0x10700001,
	},
	// #endregion

	// #region 08 可用性监测基础函数
	'[08]创建任务失败': {
		deleted: true,
		code: 0x10800001,
	},
	'[08]任务结果获取失败': {
		deleted: true,
		code: 0x10800002,
	},
	'[08]处理扫描结果出错': {
		deleted: true,
		code: 0x10800003,
	},
	'[08]扫描失败': {
		code: 0x10800004,
	},
	'[08]保存可用性监测任务ID失败': {
		code: 0x10800005,
	},
	// #endregion

	// #region 0a 告警
	'[0A][发送验证码]获取验证码缓存失败': {
		code: 0x10a00001,
	},
	'[0A][发送验证码]发送过于频繁': {
		code: 0x00a01002,
	},
	'[0A][发送验证码]保存验证码信息失败': {
		code: 0x10a00003,
	},
	'[0A][发送验证码]发送验证码失败': {
		code: 0x10a00004,
	},
	'[0A][验证收到的验证码]验证码不匹配': {
		code: 0x00a01006,
	},
	'[0A][验证收到的验证码]查询验证码缓存失败': {
		code: 0x10a00007,
	},
	'[0A][验证收到的验证码]保存成功验证码缓存失败': {
		code: 0x10a00008,
	},
	'[0A][更新告警人]查找告警人失败': {
		code: 0x10a00009,
	},
	'[0A][创建告警人]更新余额失败': {
		code: 0x10a0000a,
	},
	'[0A][删除告警人]更新余额失败': {
		code: 0x10a0000b,
	},
	'[0A][绑定微信]查询对应用户信息失败': {
		code: 0x10a0000c,
	},
	'[0A][绑定微信]读取二维码失败': {
		code: 0x10a0000d,
	},
	'[0A][绑定微信]用户已绑定微信': {
		code: 0x10a0000e,
	},
	'[0A][解绑微信]查询对应用户信息失败': {
		code: 0x10a0000f,
	},
	'[0A][绑定微信]解绑微信失败': {
		code: 0x10a00010,
	},
	'[0A][绑定微信]更新用户信息失败': {
		code: 0x10a00011,
	},
	'[0A][检查微信绑定状态]查询对应用户信息失败': {
		code: 0x10a00012,
	},
	'[0A][检查微信绑定状态]请求失败': {
		code: 0x10a00013,
	},
	'[0A][告警列表]告警列表新增信息失败': {
		code: 0x10a00014,
	},
	'[0A][发送告警]告警信息发送失败': {
		code: 0x10a00015,
	},
	'[0A][添加告警人]已添加该名称联系人': {
		code: 0x00a01016,
	},
	'[0A][绑定微信]请求二维码URL失败': {
		code: 0x10a00017,
	},
	'[0A][添加告警人]联系方式已绑定其他联系人': {
		code: 0x00a01018,
	},
	'[0A][添加告警人]保存Mongo记录失败': {
		code: 0x10a00019,
	},
	'[0A][添加告警组]已添加该名称告警组': {
		code: 0x00a0101a,
	},
	'[0A][添加告警组]保存Mongo记录失败': {
		code: 0x10a0001b,
	},
	'[0A][编辑告警人]和已有告警人重名': {
		code: 0x00a0101c,
	},
	'[0A][编辑告警人]查找重名Mongo记录失败': {
		code: 0x10a0001d,
	},
	'[0A][编辑告警组]和已有告警组重名': {
		code: 0x00a0101e,
	},
	'[0A][编辑告警组]查找重名Mongo记录失败': {
		code: 0x10a0001f,
	},
	'[0A]编辑告警人失败：联系方式已绑定其他联系人': {
		code: 0x00a01020,
	},
	'[0A][编辑告警人]保存Mongo记录失败': {
		code: 0x00a01021,
	},
	'[0A][发送告警信息]告警邮件/短信/微信发送失败': {
		code: 0x00a01022,
	},
	'[0A][发送告警信息]更新任务告警状态失败': {
		code: 0x00a00023,
	},
	'[0A][添加告警人]读取验证码缓存失败': {
		code: 0x00a00024,
	},
	'[0A][编辑告警人]读取验证码缓存失败': {
		code: 0x00a00025,
	},
	'[0A][编辑告警人]保存失败': {
		code: 0x00a00026,
	},
	'[OA][添加告警人]该手机号码已添加': {
		code: 0x00a01027,
	},
	'[OA][添加告警人]该邮箱已添加': {
		code: 0x00a01028,
	},
	'[0A]告警统计失败': {
		code: 0x00a01029,
	},
	// #endregion

	// #region 0d 网站画像
	'[0D][更新网站画像]查询对应任务信息失败': {
		code: 0x10d00003,
	},
	'[0D][更新网站画像]没有查询到对应任务信息': {
		code: 0x10d00004,
	},
	'[0D][更新网站画像]保存失败': {
		code: 0x10d00005,
	},
	// #endregion

	// #region 0E 基础模块
	'[0E]检查是否启用创宇盾失败': {
		code: 0x10e00001,
	},
	'[0E]邮件发送：邮件发送失败': {
		code: 0x10e00007,
	},
	'[0E]检查域名所属权失败': {
		code: 0x10e00009,
	},
	'[0E]短信发送失败': {
		code: 0x10e0000a,
	},
	'[0E]发送微信消息失败': {
		code: 0x10e0000b,
	},
	'[0E][检查是否使用创宇盾]查询数据库失败': {
		code: 0x10e0000c,
	},
	'[0E]检查是否使用创宇盾失败': {
		code: 0x10e0000d,
	},
	'[0E]初始化用户默认告警人/组信息失败': {
		code: 0x10e0000e,
	},
	'[0E][发送告警邮件]查询当前套餐余额失败': {
		code: 0x10e0000f,
	},
	'[0E][发送告警邮件]通过uid查询告警组失败': {
		code: 0x10e00010,
	},
	'[0E][发送告警邮件]查询告警组失败': {
		code: 0x10e00011,
	},
	'[0E][发送告警邮件]发送告警邮件失败': {
		code: 0x10e00012,
	},
	'[0E][发送告警邮件]更新提示信息发送日志失败': {
		code: 0x10e00013,
	},
	'[0E][发送告警邮件]创建告警发送记录失败': {
		code: 0x10e00014,
	},
	'[0E][发送告警信息]更新告警发送记录失败': {
		code: 0x10e00015,
	},
	'[0E][发送告警恢复信息]初始化任务告警状态失败': {
		code: 0x10e00017,
	},
	'[0E][发送告警信息]更新任务告警状态失败': {
		code: 0x10e00018,
	},
	'[0E]请求漏洞插件列表失败': {
		code: 0x10e00019,
	},
	'[0E]请求漏洞插件类别列表失败': {
		code: 0x10e0001a,
	},

	// #endregion

	// #region 0F 套餐/充值
	'[0F][余额更新]查询余额Mongo记录失败': {
		code: 0x10f00001,
	},
	'[0F][余额更新]更新Mongo记录失败': {
		code: 0x10f00002,
	},
	'[0F]初始化Mongo套餐信息失败': {
		code: 0x10f00003,
	},
	'[0F]初始化新用户套餐: 初始化Mongo记录失败': {
		code: 0x10f00004,
	},
	'[0F]系统定时任务执行失败': {
		deleted: true,
		code: 0x10f00005,
	},
	'[0F]系统定时任务队列处理失败': {
		deleted: true,
		code: 0x10f00006,
	},
	'[0F][余额更新]没有查询到对于余额Mongo记录': {
		code: 0x10f00007,
	},
	'[0F]增加额度：没有查找到对于用户余额Mongo记录': {
		code: 0x10f00008,
	},
	'[0F]更新额度定时任务：保存余额Mongo记录失败': {
		code: 0x10f00009,
	},
	'[0F][检查余额]查询余额Mongo记录失败': {
		code: 0x10f0000a,
	},
	'[0F][检查余额]没有查询到对于余额Mongo记录': {
		code: 0x10f0000b,
	},
	'[0F][检查余额]当前余额不足以执行该操作': {
		code: 0x10f0100c,
	},
	'[0F][充值]附加包充值失败': {
		code: 0x10f0000d,
	},
	'[0F][充值]套餐充值失败': {
		code: 0x10f0000e,
	},
	'[0F][充值]余额信息更新失败': {
		code: 0x10f0000f,
	},
	'[0F][充值]余额信息查询失败': {
		code: 0x10f00010,
	},
	'[0F]初始化Mongo充值包信息失败': {
		code: 0x10f00012,
	},
	'[0F][初始化用户套餐]查询套餐信息失败': {
		code: 0x10f00013,
	},
	'[0F][初始化用户套餐]保存Mongo记录失败': {
		code: 0x10f00014,
	},
	'[0F][添加套餐功能到权限信息]查询缓存失败': {
		code: 0x10f00015,
	},
	'[0F][添加套餐功能到权限信息]查询余额Mongo记录失败': {
		code: 0x10f00016,
	},
	'[0F][充值]已使用余额超出当前充值套餐可用值': {
		code: 0x10f01017,
	},
	'[0F][余额更新]套餐已过期': {
		code: 0x10f01018,
	},
	'[0F][检查余额]套餐已过期': {
		code: 0x10f01019,
	},
	'[0F][余额更新]未购买套餐': {
		code: 0x10f0101a,
	},
	'[0F][检查余额]未购买套餐': {
		code: 0x10f0101b,
	},
	'[0F][充值]使用超量': {
		code: 0x10f0101c,
	},
	// #endregion

	// #region 12 user
	'[12][新建用户]查询Mongo失败': {
		code: 0x11200001,
	},
	'[12][新建用户]初始化余额信息Mongo记录失败': {
		code: 0x11200002,
	},
	'[12][新建用户]查询CAS用户失败': {
		code: 0x11200003,
	},
	'[12][新建用户]创建CAS用户失败': {
		code: 0x11200004,
	},
	'[12]用户日志下载失败': {
		code: 0x11200005,
	},
	'[12]查询用户关联套餐失败': {
		code: 0x11200006,
	},
	// #endregion

	// #region 13 news
	'[13][新闻列表]新闻列表查询失败': {
		code: 0x11300001,
	},
	'[13][新闻列表]新建新闻信息失败': {
		code: 0x11300002,
	},
	'[13][新闻列表]新闻批量删除失败': {
		code: 0x11300003,
	},
	'[13][新闻列表]根据id删除新闻失败': {
		code: 0x11300004,
	},
	'[13][新闻列表]新闻信息更新失败': {
		code: 0x11300005,
	},
	// #endregion

	// #region 14 audit 审计日志
	'[14]操作日志下载失败': {
		code: 0x11400001,
	},
	'[14]登录日志下载失败': {
		code: 0x11400002,
	},
	// #endregion

	// #region 14 dashboard 报表
	'[15]报表报告数据生成失败': {
		code: 0x11500001,
	},
	'[15]报表报告生成失败': {
		code: 0x11500002,
	},
	// #endregion
};

export const isKuiperServerCustomError = Symbol('isKuiperServerCustomError');
export class KuiperServerCustomError extends Error {
	#errorCode;

	constructor({ component, message, publicMessage = '系统错误', code }) {
		super(publicMessage);

		this.name = this.constructor.name;
		Error.captureStackTrace(this, this.constructor);

		this.#errorCode = code;
		this.component = component;
		this.publicMessage = publicMessage;
		this.isInternalError = this.code.slice(3, 5) === '00';
		this.internalMessage = message.split(']').slice(-1).join(']');
		this.message = `[${this.code}]${
			this.isInternalError ? publicMessage : this.internalMessage
		}`;
		this.rawMessage = message;
		this[isKuiperServerCustomError] = true;
	}

	get code() {
		return this.#errorCode.toString(16).padStart(8, '0').toUpperCase();
	}

	get detail() {
		return `[${this.code}]${this.internalMessage}`;
	}

	boomify(options = {}) {
		return new Boom(this, {
			...options,
			data: {
				...(options.data || {}),
				code: this.code,
			},
		});
	}

	from(error) {
		if (error[isKuiperServerCustomError]) {
			this.#errorCode = error.code;
			this.message = `[${this.code}]${
				error.isInternalError ? this.publicMessage : error.internalMessage
			}`;
			this.isInternalError = error.isInternalError;
		} else if (error.code && error.code.toString(16).length === '8') {
			this.#errorCode = error.code;
			this.message = error.message || error.msg;
		}

		this.rawMessage = error.message;
		this.stack = error.stack;

		return this;
	}

	cause(error) {
		return this.from(error);
	}

	msg(msg) {
		if (!msg) return this;
		this.message = `[${this.code}]${String(msg).replace(/\[\w{8}\]/, '')}`;
		return this;
	}

	addition(data) {
		this.addition = data;
		return this;
	}

	messageSuffix(message) {
		this.message += `, ${message}`;
		this.internalMessage += `, ${message}`;
		return this;
	}
}

export default function errorCodesBuilder(
	publicMessage,
	errorCodes = defaultErrorCodes
) {
	return new Proxy(errorCodes, {
		get(obj, message) {
			if (!obj[message]) {
				if (process.env.NODE_ENV === 'development') {
					throw new Error(`未知错误: ${message}`);
				} else {
					return new Error(`未知错误: ${message}`);
				}
			}

			const { code, component } = obj[message] || { code: '0' };

			return new KuiperServerCustomError({
				code,
				component,
				publicMessage,
				message,
			});
		},
	});
}
